﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<CRM.Models.DistributionChannels>>" %>
<%@ Import Namespace="CRM.Models" %>
<%@ Import Namespace="CRM.Resourses" %>
<%@ Import Namespace="System.Threading" %>

<% Html.DevExpress().GridView(settings =>
                                    {
                                        settings.Name = "gdDistributionChannels";
                                        settings.KeyFieldName = "IdDistributionChannel";
                                        settings.CallbackRouteValues =
                                            new { Controller = "Dictionaries", Action = "DistributionChannelsPartial" };
                                        settings.SettingsPager.PageSize = 20;
                                       
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.DistributionChannelsPeriod;
                                            column.FieldName = "Period";
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.DistributionChannelsAmount;
                                            column.FieldName = "Amount";
                                        });

                                        //
                                        //Добавление комбобоксов
                                        //
                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdCustomer";
                                            column.Caption = Resourses.Customers;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;

                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                               
                                                comboBoxProperties.DataSource =
                                                    DB.Customers;
                                                 
                                                comboBoxProperties.TextField = "Name";
                                                comboBoxProperties.ValueField = "IdCustomer";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdDistributionChannelType";
                                            column.Caption = Resourses.DistributionChannelTypes;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;

                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                              
                                                comboBoxProperties.DataSource =
                                                    DB.GetLocalizedDistributionChannelTypesNames(Thread.CurrentThread.CurrentCulture.ToString());
                                                comboBoxProperties.TextField = "LocaLizedString";
                                                comboBoxProperties.ValueField = "Id";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                        //конец комбобокса

                                        
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.IsActive;
                                            column.FieldName = "IsActive";
                                            column.ColumnType = MVCxGridViewColumnType.CheckBox;
                                        });

                                        //
                                        //Добавление редактирования
                                        //
                                        settings.CommandColumn.Visible = true;
                                        settings.CommandColumn.NewButton.Visible = true;
                                        settings.CommandColumn.DeleteButton.Visible = true;
                                        settings.CommandColumn.EditButton.Visible = true;
                                        settings.SettingsBehavior.ConfirmDelete = true;
                                        settings.Settings.ShowFilterRow = true;
                                        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Dictionaries", Action = "DistributionChannelsPartialUpdate" };
                                        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Dictionaries", Action = "DistributionChannelsPartialAdd" };
                                        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Dictionaries", Action = "DistributionChannelsPartialDelete" };

                                        settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
                                        settings.Width = Unit.Percentage(100);

                                        
                                    })
       .Bind(Model).GetHtml();
%>

